package com.yingluo.abacus.boot.core.data.hibernate.dao;

import java.util.List;


public class Pagination<T> {
	// 分页信息
	private Long nowpage;// 当前页
	private Long countrecord;// 总记录
	private Long countpage;// 总页数

	public  Long pagesize = ICCPage.PAGESIZE;// 每页显示的记录数

	private Long startpage;// 页面中的起始页
	private Long endpage;// 页面中的结束页、
//	private Long startrecord;// 当前页起始行
//    private Long endrecord;// 结束行

	private final Long SHOWPAGE = 6L;// 

	private List<T> allentities;

	/** 根据当前页及总记录数来构造分页对象 */
	public void init( ) {

		/** 计算总页数 */
		this.countpage = this.countrecord % this.pagesize == 0 ? this.countrecord / this.pagesize
				: this.countrecord / this.pagesize + 1;

		/** 计算startpage与endpage的值 */

		/** 总页数数是否小于4 */
		if (this.countpage < (this.SHOWPAGE / 2 + 1)) {
			this.startpage = 1L; // 页面中起始页就是1
			this.endpage = this.countpage;// 页面中的最终页就是总页数
		} else {
			/** else中是总页数大于4的情况 */

			/** 首先当前页的值是否小于等于4 */
			if (this.nowpage <= (this.SHOWPAGE / 2 + 1)) {
				this.startpage = 1L;
				this.endpage = this.nowpage + 2;
				/** 判断页面的最终页是否大于总页数 */
				if (this.endpage >= this.countpage) {
					this.endpage = this.countpage;
				}
			} else {
				this.startpage = this.nowpage - 3;
				this.endpage = this.nowpage + 2;

				if (this.endpage >= this.countpage) {
					this.endpage = this.countpage;
					if (this.countpage < this.SHOWPAGE) {
						this.startpage = 1L;
					} else {
						this.startpage = this.endpage - 5;
					}

				}
			}
		}
	}
	public void init(Long nowpage, Long countrecord) {
		this.nowpage = nowpage;
		this.countrecord = countrecord;
		init();

	}

	public Pagination() { 
		pagesize = ICCPage.PAGESIZE;
		nowpage=ICCPage.STARTPAGE;
	}

	public Pagination(Long nowpage, Long countrecord) {
		init(nowpage,countrecord);
	}

	public Long getNowpage() {
		return nowpage;
	}

	public void setNowpage(Long nowpage) {
		this.nowpage = nowpage;
	}

	public Long getCountrecord() {
		return countrecord;
	}

	public void setCountrecord(Long countrecord) {
		this.countrecord = countrecord;
	}

	public Long getCountpage() {
		return countpage;
	}

	public void setCountpage(Long countpage) {
		this.countpage = countpage;
	}

	public Long getStartpage() {
		return startpage;
	}

	public void setStartpage(Long startpage) {
		this.startpage = startpage;
	}

	public Long getEndpage() {
		return endpage;
	}

	public void setEndpage(Long endpage) {
		this.endpage = endpage;
	}

	public List<T> getAllentities() {
		return allentities;
	}

	public void setAllentities(List<T> allentities) {
		this.allentities = allentities;
	}

	public Long getPagesize() {
		return pagesize;
	}

	public void setPagesize(Long pagesize) {
		this.pagesize = pagesize;
	}

}
